package com.fly.caihong.frag;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;

import com.fly.caihong.R;
import com.fly.caihong.activity.MainActivity;
import com.fly.caihong.base.BaseFragment;
import com.fly.caihong.utils.ActivityUtils;
import com.fly.caihong.utils.SPUtils;

public class WelcomeFragment extends BaseFragment {

    public static Fragment newInstance(int position) {
        WelcomeFragment fragment = new WelcomeFragment();
        Bundle args = new Bundle();
        args.putInt("position", position);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initView(View view) {
        int position = getArguments().getInt("position");
        view.setBackgroundResource(position == 0 ? R.drawable.ic_meishi_bg
                : position == 1 ? R.drawable.ic_wenhua_bg : R.drawable.ic_shishang_bg);
        if (position == 2) {
            View btnFirstGo = view.findViewById(R.id.btn_first_go);
            btnFirstGo.setVisibility(View.VISIBLE);
            btnFirstGo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    SPUtils.getInstance().put("guide", true);
                    ActivityUtils.startActivity(getActivity(), MainActivity.class);
                    getActivity().finish();
                    //后续要加入sp，非首次不在展示
                }
            });
        }
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_welcome;
    }
}
